# -*- coding:utf-8
# 5178. 四因数 显示英文描述
# 用户通过次数235
# 用户尝试次数474
# 通过次数235
# 提交次数642
# 题目难度Medium
# 给你一个整数数组 nums，请你返回该数组中恰有四个因数的这些整数的各因数之和。
#
# 如果数组中不存在满足题意的整数，则返回 0 。

from typing import List
import math

class Solution:

    def getNum(self,num:int):
        yinshus = []
        a = int(math.sqrt(num))+1
        cur = 1
        while cur< a:
            if num%cur == 0 and cur*cur != num:
                yinshus.append(cur)
                yinshus.append(num/cur)
            cur += 1
        if yinshus.__len__() == 4:
            return int(sum(yinshus))
        else:
            return 0


    def sumFourDivisors(self, nums: List[int]) -> int:
        res = 0
        for num in nums:
            res += self.getNum(num)


        return res

# class Solution:
#     def sumFourDivisors(self, nums: List[int]) -> int:
#         ans = 0
#         for num in nums:
#             # factor_cnt: 因数的个数
#             # factor_sum: 因数的和
#             factor_cnt = factor_sum = 0
#             i = 1
#             while i * i <= num:
#                 if num % i == 0:
#                     factor_cnt += 1
#                     factor_sum += i
#                     if i * i != num:   # 判断 i 和 num/i 是否相等，若不相等才能将 num/i 看成新的因数
#                         factor_cnt += 1
#                         factor_sum += num // i
#                 i += 1
#             if factor_cnt == 4:
#                 ans += factor_sum
#         return ans




res  = Solution().sumFourDivisors([1,2,3,4,5,6,7,8,9,10])
print(res)